package com.pai4j.pgc.pojo.es;

import com.chat4j.common.util.JsonUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.util.Date;

/**
 * @Author: yefazhi
 * @Create: 2021/8/29
 * @Version: 1.0
 */
@Data
public class DtoRequest {

    @JsonProperty("id")
    private String id;
    /***
     * 业务id
     */
    @JsonProperty("biz_id")
    private String bizId;
    /**
     * 资源描述
     */
    @JsonProperty("description")
    private String description;
    /**
     * 资源正文
     */
    @JsonProperty("content")
    private String content;

    @JsonProperty("data")
    private String data;
    /**
     * 作者
     */
    @JsonProperty("author")
    private String author;
    /**
     * 点击数量
     */
    @JsonProperty("click_count")
    private Integer clickCount;
    /**
     * 数据源类型：ResourceTypeEnum 中的枚举值
     */
    @JsonProperty("source_type")
    private String sourceType;
    /**
     * 创建时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonProperty("create_date")
    private Date createDate;
    /**
     * 更改时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @JsonProperty("update_date")
    private Date updateDate;

    public static DtoRequest of(String sourceType,
                                Long id,
                                String source,
                                Long clickCount,
                                String author,
                                String desc,
                                Date createDate,
                                Date updateDate,
                                Object entity) {
        return of(sourceType, String.valueOf(id), source, clickCount, author, desc, createDate, updateDate, entity);
    }

    public static DtoRequest of(String sourceType,
                                String id,
                                String source,
                                Long clickCount,
                                String author,
                                String desc,
                                Date createDate,
                                Date updateDate,
                                Object entity) {
        DtoRequest syncResourceRequestDTO = new DtoRequest();
        syncResourceRequestDTO.setId(id);
        syncResourceRequestDTO.setBizId(id);
        syncResourceRequestDTO.setClickCount(clickCount == null ? 0 : clickCount.intValue());
        syncResourceRequestDTO.setAuthor(author);
        syncResourceRequestDTO.setContent(source);
        syncResourceRequestDTO.setDescription(desc);
        syncResourceRequestDTO.setData(JsonUtil.toJsonString(entity));
        syncResourceRequestDTO.setSourceType(sourceType);
        syncResourceRequestDTO.setCreateDate(createDate);
        if (updateDate != null) {
            syncResourceRequestDTO.setUpdateDate(updateDate);
        }
        return syncResourceRequestDTO;
    }
}
